3
3
.
.
1
1
.
.
6
6
C
C
o
o
n
n
d
d
i
i
t
t
i
i
o
o
n
n
a
a
l
l
V
V
i
i
e
e
w
w
'
'
s
s
P
P
a
a
r
r
a
a
m
m
e
e
t
t
e
e
r
r
I
I
n
n
f
f
o
o
[
[
R
R
]
]
This tutorial shows how to define View's Parameter based on some condition.
E
E
x
x
a
a
m
m
p
p
l
l
e
e
In this example we change the content of Text View based on the value of accessGranted Boolean Variable.
MainActivity.kt
package com.example.testcompose
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.Text
import androidx.compose.ui.platform.setContent
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
var accessGranted = false
Text(text = if (accessGranted) { "You may proceed" } else { "Access denied" } )
}
}
}
accessGranted = true accessGranted = false